package com.ch10.config;

import com.ch10.mapper.UserMapper;
import com.ch10.mapper.impl.UserMapperImpl;
import com.ch10.service.UserService;
import com.ch10.service.impl.UserServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * @ClassName AppConfig
 * @Description 配置类,取代xml配置文件.使用@Configuration注解标识
 * @Author Kx
 * @Date 2025/4/30 9:54
 * @Version 1.0
 */
@Configuration
// 可以启用注解扫描,扫描相关的包来配置Bean
@ComponentScan(basePackages = "com.ch10")
public class AppConfig {

    /**
     * @author: kx
     * @date: 2025/4/30 11:12
     * @return com.ch10.service.UserService
     * @description: 使用@Bean注解装配一个bean,等效xml中的<bean>标签.默认id就是方法名.也可以通过@Bean注解的name属性来更改.还可以结合@Scope注解来指定作用域.最后return的对象会自动纳入IOC容器管理</>
    */
    @Bean(name="abc")
    @Scope("singleton")
    public UserService userService() {
        return new UserServiceImpl(userMapper());
    }

    /**
     * @author: kx
     * @date: 2025/4/30 11:09
     * @return com.ch10.mapper.UserMapper
     * @description: 配置UserMapper的Bean
    */
    @Bean
    public UserMapper userMapper() {
        return new UserMapperImpl();
    }
}
